package com.hy.admin.enums;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;

/**
 * Created by wayne on 18/4/22.
 */
public enum  EnumPayOrderStatus {
    /**
     * 待支付
     */
    DUE_PAY(1, "待支付"),

    /**
     * 支付中
     */
    PAYING(2, "支付中"),

    /**
     * 支付成功
     */
    PAY_SUCCESS(3, "支付成功"),

    /**
     * 支付失败
     */
    PAY_FAIL(5, "支付失败"),

    /**
     * 已经退款
     */
    REFUNDED(6, "已经退款"),

    /**
     * 已经关闭订单
     */
    CLOSE(7, "已关闭订单"),

    /**
     * 已撤销
     * */
    REVERSE(8,"已撤销订单"),

    REFUNDING(9,"申请退款")
    ;

    private int id;
    private String value;
    private boolean isreset;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    EnumPayOrderStatus(final int id, final String value) {
        this.id = id;
        this.value = value;
    }

    private static final ImmutableMap<Integer, EnumPayOrderStatus> INIT_MAP;

    static {
        final ImmutableMap.Builder<Integer, EnumPayOrderStatus> builder = new ImmutableMap.Builder<>();
        for (EnumPayOrderStatus status : EnumPayOrderStatus.values()) {
            builder.put(status.getId(), status);
        }
        INIT_MAP = builder.build();
    }

    public static EnumPayOrderStatus of(final int status) {
        Preconditions.checkState(INIT_MAP.containsKey(status), "未知的状态[{}]", status);
        return INIT_MAP.get(status);
    }

    public static String returnStatusById(int id){

        for (EnumPayOrderStatus enumPayOrderStatus:EnumPayOrderStatus.values()) {
            if (id==enumPayOrderStatus.getId())
                return enumPayOrderStatus.getValue();
        }
        return null;
    }
}

